/* Copyright 2011 Elektrobit Wireless Communications Oy (EB)


  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License version 2 as 
  published by the Free Software Foundation.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along
  with this program; if not, write to the Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.


 *All rights reserved 
 *Version:Elektrobit_Qt_1.0.0_20110305 */


#include "piccovertservice.h"
#include <services/services.h>
#include <appcommon.h>
#include <QDir>
#include <QDesktopServices>

PicCovertService::PicCovertService(QObject *parent) : Service(parent) {
    pPicCovert = NULL;
}


int PicCovertService::start(void) {
    int w=0,h=0;

    w = SERVICE(BackgroundService)->property("w").toInt()/2;
    h = SERVICE(BackgroundService)->property("h").toInt()/2;
    QStringList pathList = this->property("source_pic_paths").toString().split(";");
    bool hasDesktopPicPath = false;
    QString desktopPicPath = QDesktopServices::storageLocation(QDesktopServices::PicturesLocation);
    for(int i = 0; i < pathList.count(); i++)
    {
        QDir dir(pathList.at(i));
        if(dir.absolutePath() == desktopPicPath)
        {
            hasDesktopPicPath = true;
            break;
        }
    }
    if(!hasDesktopPicPath){
        pathList.append(desktopPicPath);
    }

    pPicCovert = new PicCovert(w,h,pathList, this->property("dest_pic_path").toString());
    return 0;
}
